package com.czh.controller;

import com.czh.constants.SystemConstants;
import com.czh.domain.ResponseResult;
import com.czh.domain.vo.LocationVo;
import com.czh.enums.AppHttpCodeEnum;
import com.czh.service.impl.LocationServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author caozaihui
 */
@RestController
public class LocationController {
    @Resource
    private LocationServiceImpl locationService;
    @GetMapping("/location")
    public ResponseResult<LocationVo> getIpAddress() {
        return locationService.getIpLocationInfo();
    }
    @GetMapping("/ipaddr")
    public ResponseResult<String> getIpAddr(HttpServletRequest request){
        locationService.setIpAddr(request);
        String ipAddr = locationService.getIpAddr();
        if (ipAddr.equals( SystemConstants.LOCATION_IP)){
            return ResponseResult.errorResult(ipAddr,AppHttpCodeEnum.LOCALHOST);
        }
        return ResponseResult.okResult(ipAddr);
    }
}
